//% color="#4169E1" iconWidth=50 iconHeight=40
namespace RainSensor{

    //% block="雨量计模块初始化 直到成功 I2C模式" blockType="command" 
    export function init(parameter: any, block: any) {

        Generator.addInclude("includlib",`#include "DFRobot_RainfallSensor.h"`);
        Generator.addObject(`addobj`, `DFRobot_RainfallSensor_I2C`, `rainSensor(&Wire);`);

        Generator.addSetup(`addsetup`,`while(!rainSensor.begin()){delay(500);}`);
   
    }


    //% block="读取上电后累计雨量(mm)" blockType="reporter"
    export function get_rainfall(parameter: any, block: any) { 
        Generator.addCode( [`rainSensor.getRainfall()`,Generator.ORDER_UNARY_POSTFIX]);
   
   }

    //% block="读取[HOUR]小时内累计雨量(mm)" blockType="reporter"
    //% HOUR.shadow="range"   HOUR.params.min=1    HOUR.params.max=24    HOUR.defl=1
    export function get_rainfall_time(parameter: any, block: any) { 
        let hour = parameter.HOUR.code;
        Generator.addCode( [`rainSensor.getRainfall(${hour})`,Generator.ORDER_UNARY_POSTFIX]);
   
   }
/*
      //% block="读取雨量翻斗次数" blockType="reporter"
      export function get_raw_data(parameter: any, block: any) { 
        Generator.addCode( [`rainSensor.getRawdata()`,Generator.ORDER_UNARY_POSTFIX]);
   
   } 
   */


}